
//
//  WSHeaderView.m
//  FD
//
//  Created by xiaofang wang on 2018/11/22.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//  3:28
// 60  + 40  = 100 
#import "WSHeaderView.h"
#define K15 (15.0)
@interface WSHeaderView()
/**送餐地址 添加手势*/
@property (nonatomic, strong) UIView *div1;
/**1.icon*/
@property (nonatomic, strong) UIImageView *iconIv;

/**div2*/
@property (nonatomic, strong) UIView *div2;
/**餐品信息*/
@property (nonatomic, strong) UILabel *canpinMessageLb;
/**灰色的线*/
@property (nonatomic, strong) UIView *lineView;

@end

@implementation WSHeaderView
#pragma mark - 一 init


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)setupView {
    [self addSubview:self.div1];
    [self.div1 addSubview:self.iconIv];
    [self.div1 addSubview:self.addressLb];
    [self.div1 addSubview:self.rightArrowIv];//可用优惠券箭头
    self.rightArrowIv.hidden = YES; //默认隐藏
    
    
    [self addSubview:self.div2];
    [self.div2 addSubview:self.canpinMessageLb];
    [self.div2 addSubview:self.lineView]; //线
}



#pragma mark - 二 getter
//!!!!:div1 白色
- (UIView *)div1 {
    if (!_div1) {
        _div1 = [UIView new];
        _div1.backgroundColor = [UIColor whiteColor];
//        _div1.backgroundColor = [UIColor redColor];

        //添加手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickSelectAddressGes)];
        [_div1 addGestureRecognizer:tap];
    }
    return _div1;
}
- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [UIImageView new];
        _iconIv.image = [UIImage imageNamed:@"address"];
    }
    return _iconIv;
}
- (UILabel *)addressLb {
    if (!_addressLb) {
        _addressLb = [UILabel new];
        //g国际化
        NSString *addressAndTime = NSLocalizedString(SelectAddressAndMealTime, @"选择送餐地址和时间");
        _addressLb.text = addressAndTime;
//        _addressLb.textColor = kLightGrayTextColor; //浅灰色文字
        _addressLb.numberOfLines = 0; //自动换行
    }
    return _addressLb;
}

//右边提示箭头
- (UIImageView *)rightArrowIv {
    if (!_rightArrowIv) {
        _rightArrowIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"可用优惠券箭头.png"]];
    }
    return _rightArrowIv;
}


//!!!!:div2
- (UIView *)div2 {
    if (!_div2) {
        _div2 = [UIView new];
        _div2.backgroundColor = [UIColor whiteColor];
    }
    return _div2;
}
- (UILabel *)canpinMessageLb {
    if (!_canpinMessageLb) {
        _canpinMessageLb = [UILabel new];
        //国际化
        NSString *cpmsg = NSLocalizedString(Home_CanPinMsg, @"餐品信息");
        _canpinMessageLb.text = cpmsg;
    }
    return _canpinMessageLb;
}
- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor rb_colorHex:0xf6f6f6];
    }
    return _lineView;
}

#pragma mark - 三 layout
// 60  + 40 + 10  = 100 + 10
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.div1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(60); //最好能自适应
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.mas_top);
    }];
    
    [self.div2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.div1.mas_bottom).offset(10);
        make.height.mas_equalTo(40);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
    }];
    
    [self layoutDiv1];
    [self layoutDiv2];
}

//!!!!:div1
- (void)layoutDiv1 {
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(K15);
        make.size.mas_equalTo(CGSizeMake(15, 20));
        make.centerY.equalTo(self.div1.mas_centerY);
    }];
    [self.addressLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(10);
        make.top.bottom.equalTo(self.div1);
        make.right.equalTo(self.rightArrowIv.mas_left);
    }];
    
    //右边箭头
    [self.rightArrowIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.right.equalTo(self.div1.mas_right).offset(-15);
        make.centerY.equalTo(self.div1.mas_centerY);
    }];
}

//!!!!:div2
- (void)layoutDiv2 {

    [self.canpinMessageLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div2.mas_left).offset(K15);
        make.height.mas_equalTo(20);
        make.width.mas_greaterThanOrEqualTo(100); //2019-2-23国际化高度自适应
        make.centerY.equalTo(self.div2);
    }];
    
    //线
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div2.mas_left).offset(15);
        make.right.equalTo(self.div2.mas_right).offset(-15);
        make.height.mas_equalTo(1);
        make.bottom.equalTo(self.div2.mas_bottom);
    }];
}


#pragma mark - 四 点击事件
- (void)clickSelectAddressGes {
    if (self.wsHeaderViewSelectAddressBlock) {
        self.wsHeaderViewSelectAddressBlock();
    }
}
@end
